package com.qf.action;

import com.qf.common.SGHelper;
import com.qf.pojo.entity.TesterDevice;
import com.qf.pojo.entity.TesterMode;
import com.qf.utils.CustomException;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @创建人: fengli
 * @创建时间: 2018/11/9 0009 9:42
 * @包: com.qf.action
 * @描述:
 */
@Controller
@RequestMapping("/app")
public class DeviceAction {
    @ResponseBody
    @RequestMapping(value = "/singleTestResultQuery")//正常测试
    public JSONObject singleTestResultQuery(HttpServletRequest request, String boxId) {
        try {
            return SGHelper.singleTestResultQuery(boxId);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }
    }

    @ResponseBody
    @RequestMapping(value = "/PressureTestResultsQuery")//压力测试
    public JSONObject PressureTestResultsQuery(HttpServletRequest request, TesterDevice testerDevice) {
        try {
            return SGHelper.PressureTestResultsQuery(testerDevice);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getDeviceStatusToMtms")
    public String getDeviceStatusToMtms(HttpServletRequest request, String boxId, String tenantId) {
        try {
            return SGHelper.getDeviceStatusToMtms(boxId, tenantId);
        } catch (CustomException e) {
            return "{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}";
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBoxIdAndTestResult")
    public JSONObject getBoxIdAndTestResult(HttpServletRequest request, TesterMode testerMode) {
        try {
            return SGHelper.getBoxIdAndTestResult(testerMode);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }
    }

    @ResponseBody
    @RequestMapping(value = "/boxIdValidation")
    public JSONObject boxIdValidation(HttpServletRequest request, String testerId, String tenantId, String boxId, String productId) {
        try {
            return SGHelper.boxIdValidation(testerId, tenantId, boxId, productId);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }
    }

    @ResponseBody
    @RequestMapping(value = "/ToStopTesting")
    public JSONObject ToStopTesting(HttpServletRequest request, String ids){
        try {
            return SGHelper.ToStopTesting(ids);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }
    }

    @ResponseBody
    @RequestMapping(value = "/startTest")
    public JSONObject startTest(HttpServletRequest request, String testerId, String tenantId, String productId, String ids) {
        try {
            return  SGHelper.startTest(testerId, tenantId, productId, ids);
        } catch (CustomException e) {
            return JSONObject.fromObject("{\"code\":\"-2000\",\"msg\":\"" + e.getMessage() + "\"}");
        }
    }


}
